import ChannelManager from "../scripts/manager/ChannelManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class demo extends cc.Component {

    start() {
        this.node.getChildByName("btn_toast").on(cc.Node.EventType.TOUCH_END, this.onToast, this);
        this.node.getChildByName("btn_dialog_1").on(cc.Node.EventType.TOUCH_END, this.onDialog1, this);
        this.node.getChildByName("btn_dialog_2").on(cc.Node.EventType.TOUCH_END, this.onDialog2, this);
        this.node.getChildByName("btn_dialog_3").on(cc.Node.EventType.TOUCH_END, this.onDialog3, this);
        this.node.getChildByName("btn_loading").on(cc.Node.EventType.TOUCH_END, this.showLoading, this);
        this.node.getChildByName("btn_ads").on(cc.Node.EventType.TOUCH_END, this.onShowAds, this);
    }

    /**
     * Toast提示
     */
    private onToast() {
        ChannelManager.GetInstance().ShowToast("toast提示测试");
    }

    /**
     * 显示提示框
     */
    private onDialog1() {
        ChannelManager.GetInstance().ShowDialog({
            title: "提 示",
            content: "Dialog测试1，常规提示框",
            sure: function () {
                console.log("Dialog测试1", ">>>>>sure");
            },
            cancel: function () {
                console.log("Dialog测试1", ">>>>>cancel");
            }
        });
    }

    /**
     * 显示提示框，仅显示关闭按键
     */
    private onDialog2() {
        ChannelManager.GetInstance().ShowDialog({
            title: "提 示",
            content: "Dialog测试2，显示提示框，仅显示关闭按键",
            sure_label: "关 闭"
        });
    }

    /**
     * 显示提示框，显示广告icon
     */
    private onDialog3() {
        ChannelManager.GetInstance().ShowDialog({
            title: "提 示",
            content: "Dialog测试3，显示提示框，显示广告icon",
            sure: function () {
                console.log("Dialog测试3", ">>>>>sure");
            },
            cancel: function () {
                console.log("Dialog测试3", ">>>>>cancel");
            },
            ad_icon: true
        });
    }

    private onShowAds() {
        console.log(">>>>>>>>>>>>>>>>", 1);
        ChannelManager.GetInstance().ShowTestAd(function () {
            console.log("播放成功,获得奖励");
        }.bind(this), function () {
            console.log("播放失败,放弃奖励");
        }.bind(this));
    }
    private showLoading() {
        ChannelManager.GetInstance().ShowLoading();
        this.scheduleOnce(() => {
            ChannelManager.GetInstance().HideLoading();
        }, 3);
    }
}
